import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  strict: process.env.NODE_ENV === 'development',
  state: {
    money: 999,
    car: '宝马'
  },
  mutations: {
    less(state) {
      state.money -= 10
    },
    buy(state) {
      state.money -= 50
    },
    add(state) {
      state.money++
    },

    addFn(state, val) {
      state.money += val
    },

    doHair(state, val) {
      state.money -= val
    }
  },

  actions: {
    doHairAsync(context, num) {
      // 一秒后, 给一个数, 去修改 num
      setTimeout(() => {
        context.commit('doHair', num)
      }, 1000)
    }
  },
})

export default store